package pers.qianyu.config;

import lombok.extern.slf4j.*;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.config.annotation.*;
import pers.qianyu.interceptor.*;

import javax.annotation.*;

/**
 * @author mizzle rain
 * @date 2020-10-14 10:10
 */
@Slf4j
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Resource
    private RateLimitInterceptor rateLimitInterceptor;

    /**
     * 向 Web 添加拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(rateLimitInterceptor)
                .addPathPatterns("/api/**");
    }

    /**
     * 静态资源配置
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 上传的文件被保存的位置
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:E:/Codes/scaffold/eagle/uploads/");
        // Knife4j 资源
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
